﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../../styles/global_color.css"/>
    <script src="../../js/jquery-3.2.1.js"></script>
    <script language="javascript" type="text/javascript">
        //显示角色详细信息
        function showDetail(flag, a) {
            var detailDiv = a.parentNode.getElementsByTagName("div")[0];
            if (flag) {
                detailDiv.style.display = "block";
            }
            else
                detailDiv.style.display = "none";
        }
        //重置密码
        function resetPwd() {
            var admins = [];
            $("input[name=check]").each(function (i, d) {
                if (d.checked) {
                    admins.push(d.value);
                }
            });
            if (admins.length < 1) {
                alert("请至少选择一个");
            } else {
                //重置密码
                $.ajax({
                    url: "/resetpass",
                    data: {
                        "admins": admins
                    },
                    type: "post",
                    success: function () {
                        alert("重置密码成功");
                    }
                })
            }
        }
        //删除
        function deleteAdmin(adminId) {
            var r = window.confirm("确定要删除此管理员吗？");
            if (r) {
                $.ajax({
                    url: "/deleteAdmin",
                    type: "post",
                    data: {
                        adminId: adminId
                    },
                    success: function () {
                        document.getElementById("operate_result_info").style.display = "block";
                        window.location.href = "/adminList";
                    }
                });
            }
        }
        //全选
        function selectAdmins(inputObj) {
            var inputArray = document.getElementById("datalist").getElementsByTagName("input");
            for (var i = 1; i < inputArray.length; i++) {
                if (inputArray[i].type == "checkbox") {
                    inputArray[i].checked = inputObj.checked;
                }
            }
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li><a href="/rolelist" class="role_off"></a></li>
        <li><a href="/adminList" class="admin_off"></a></li>
        <li><a href="/feelist" class="fee_off"></a></li>
        <li><a href="/accountlist" class="account_off"></a></li>
        <li><a href="/servicelist" class="service_off"></a></li>
        <li><a href="/billList" class="bill_off"></a></li>
        <li><a href="/reportList" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModiPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <div>
                模块：
                <select id="selModules" class="select_search">
                    <option>全部</option>
                    <option>角色管理</option>
                    <option>管理员管理</option>
                    <option>资费管理</option>
                    <option>账务账号</option>
                    <option>业务账号</option>
                    <option>账单管理</option>
                    <option>报表</option>
                </select>
            </div>
            <div>角色：<input type="text" value="" class="text_search width200"/></div>
            <div><input type="button" value="搜索" class="btn_search"/></div>
            <input type="button" value="密码重置" class="btn_add" onclick="resetPwd();"/>
            <input type="button" value="增加" class="btn_add" onclick="window.location.href='/adminAdd';"/>
        </div>
        <!--删除和密码重置的操作提示-->
        <div id="operate_result_info" class="operate_fail">
            <img src="../../images/close.png" onclick="this.parentNode.style.display='none';"/>
            <span>删除失败！数据并发错误。</span><!--密码重置失败！数据并发错误。-->
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th class="th_select_all">
                        <input type="checkbox" onclick="selectAdmins(this);"/>
                        <span>全选</span>
                    </th>
                    <th>管理员ID</th>
                    <th>姓名</th>
                    <th>登录名</th>
                    <th>电话</th>
                    <th>电子邮件</th>
                    <th>授权日期</th>
                    <th class="width100">拥有角色</th>
                    <th></th>
                </tr>
            </table>
        </div>
        <!--分页-->
        <div id="pages">
        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <span>版权所有(C)云科技有限公司 </span>
</div>
<script src="../../js/jquery-3.2.1.js"></script>
<script src="../../js/parseDate.js"></script>
<script>
    var ip = 1;
    $.ajax({
        url: "/adminPage",
        data: {
            pagenum: ip
        },
        type: "post",
        success: function (data) {
            for (var i in data.list) {
                var admin = data.list[i];
                var adminId = admin.adminId;
                var name = admin.name;
                var adminCode = admin.adminCode;
                var telephone = admin.telephone;
                var email = admin.email;
                var date = admin.enrolldate;
                var enrolldate = getLocalTime(date);
                for (var j in admin.roleList) {
                    var rlist = admin.roleList[j];
                    var names = rlist.name;
                    $("#datalist").append("<tr><td><input type='checkbox' value='" + adminId + "' name='check'/></td><td>" + adminId + "</td><td>" + name + "</td><td>" + adminCode + "</td><td>" + telephone + "</td><td>" + email + "</td><td>" + enrolldate + "</td><td>" + names + "</td><td class='td_modi'><input type='button' value='修改' class='btn_modify' onclick='updateAdmin(" + adminId + ");' /> <input type='button' value='删除' class='btn_delete' onclick='deleteAdmin(" + adminId + ");'/></td></tr>");
                }
            }
//            当前页码
            var pageNum = data.pageNum;
//            每页的数量
            var pageSize = data.pageSize;
//            当前页的数量
            var size = data.size;
//            数据总数
            var total = data.total;
//            一共多少页
            var pages = data.pages;
//            首页是多少
            var firstPage = data.firstPage;
//            上一页是多少
            var prePage = data.prePage;
//            下一页是多少
            var nextPage = data.nextPage;
//            最后一页是多少
            var lastPage = data.lastPage;
//            是否是首页
            var isFirstPage = data.isFirstPage;
//            是否是尾页
            var isLastPage = data.isLastPage;
            if (isFirstPage) {
                prePage = prePage + 1;
            }
            if (isLastPage) {
                nextPage = lastPage;
            }
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + prePage + ")'>" + "<<<" + "</a>"));
            for (i = 1; i <= lastPage; i++) {
                $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + i + ")'>" + i + "</a>"))
            }
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + nextPage + ")'>" + ">>>" + "</a>"));
            var urlstatus = false;
            if (!urlstatus) {
                $("#pages a").eq(1).addClass('current_page');
            }
        }
    });

    function page(i) {
//        alert("点击事件参数" + i)
        ip = i;
        $.ajax({
            url: "/adminPage",
            data: {
                pagenum: ip
            },
            type: "post",
            success: function (data) {
                $("#datalist").html("");
                $("#datalist").append("<tr><th class='th_select_all'><input type='checkbox' onclick='selectAdmins(this);'/><span>全选</span></th><th>管理员ID</th><th>姓名</th><th>登录名</th><th>电话</th><th>电子邮件</th><th>授权日期</th><th class='width100'>拥有角色</th><th></th></tr>");
                console.log(data);
                for (var i in data.list) {
                    var admin = data.list[i];
                    var adminId = admin.adminId;
                    var name = admin.name;
                    var adminCode = admin.adminCode;
                    var telephone = admin.telephone;
                    var email = admin.email;
                    var date = admin.enrolldate;
                    var enrolldate = getLocalTime(date);
                    for (var j in admin.roleList) {
                        var rlist = admin.roleList[j];
                        var names = rlist.name;
                        $("#datalist").append("<tr><td><input type='checkbox' value='" + adminId + "' name='check'/></td><td>" + adminId + "</td><td>" + name + "</td><td>" + adminCode + "</td><td>" + telephone + "</td><td>" + email + "</td><td>" + enrolldate + "</td><td>" + names + "</td><td class='td_modi'><input type='button' value='修改' class='btn_modify' onclick='updateAdmin(" + adminId + ");'/> <input type='button' value='删除' class='btn_delete' onclick='deleteAdmin(" + adminId + ");'/></td></tr>");
                    }
                }
//            当前页码
                var pageNum = data.pageNum;
//            每页的数量
                var pageSize = data.pageSize;
//            当前页的数量
                var size = data.size;
//            数据总数
                var total = data.total;
//            一共多少页
                var pages = data.pages;
//            首页是多少
                var firstPage = data.firstPage;
//            上一页是多少
                var prePage = data.prePage;
//            下一页是多少
                var nextPage = data.nextPage;
//            最后一页是多少
                var lastPage = data.lastPage;
//            是否是首页
                var isFirstPage = data.isFirstPage;
//            是否是尾页
                var isLastPage = data.isLastPage;
                if (isFirstPage) {
                    prePage = prePage + 1;
                }
                if (isLastPage) {
                    nextPage = lastPage;
                }
                $("#pages").html("");
                $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + prePage + ")'>" + "<<<" + "</a>"));
                for (i = 1; i <= lastPage; i++) {
                    $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + i + ")'>" + i + "</a>"))
                }
                $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + nextPage + ")'>" + ">>>" + "</a>"));
                $("#pages a").siblings('a').removeClass('selected');
                $("#pages a").eq(pageNum).addClass('current_page');
            }
        });
    }

    function updateAdmin(adminId) {
        window.location.href = '/adminUpdate?adminid=' + adminId + '';
    }
</script>
</body>
</html>
